package com.ssy.lingxi.member.merchant.controller.mobile;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.bo.MobileLoginBO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.PhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobileLoginVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobilePhoneLoginVO;
import com.ssy.lingxi.member.merchant.service.mobile.IMobileWechatAppletLoginService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author 郑小翠
 * @version 2.02.18
 * @menu 微信小程序-业务员登录
 * @date 2022-03-23
 */
@RestController
@RequestMapping("/member/mobile/wechat/applet")
public class MobileWechatAppletLoginController {

    @Resource
    private IMobileWechatAppletLoginService mobileWechatAppletLoginService;

    /**
     * 账号登录
     *
     * @param headers Http头部信息
     * @param loginVO 接口参数
     * @return 登录用户信息
     */
    @RequestMapping(value = "/login/account", method = RequestMethod.POST)
    public Wrapper<MobileLoginBO> accountLogin(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobileLoginVO loginVO) {
        return mobileWechatAppletLoginService.accountLogin(headers, loginVO);

    }

    /**
     * 发送“手机号登录”的短信验证码
     *
     * @param headers Http头部信息
     * @param phoneVO 接口参数
     * @return 发送结果
     */
    @RequestMapping(value = "/sends", method = RequestMethod.POST)
    public Wrapper<Void> sendPhoneLoginSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneVO phoneVO) {
        return mobileWechatAppletLoginService.sendPhoneLoginSmsCode(headers, phoneVO);
    }

    /**
     * 手机号登录
     *
     * @param headers Http头部信息
     * @param loginVO 接口参数
     * @return 登录用户信息
     */
    @RequestMapping(value = "/login/phone", method = RequestMethod.POST)
    public Wrapper<MobileLoginBO> phoneLogin(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobilePhoneLoginVO loginVO) {
        return mobileWechatAppletLoginService.phoneLogin(headers, loginVO);
    }

}
